
		
			<div class="page-header settingheading">
			  <h4>Search Friends</h4>
			</div>
			<div class="row">
				<div class="col-lg-12">
					<div class="alert alert-zap text-right">
						<form action="<?php echo base_url(); ?>users/searchfriends" method="get" id="search_form">
							<div class="input-group">
								<input type="text" class="form-control" name="search" id="search">
								<span class="input-group-btn">
									<button class="btn btn-default" type="submit">Search</button>
								</span>
							</div>
						</form>
					</div>	
				</div>
			</div>
			<!--Search Results -->
			<div class="row">
				<?php if(isset($zapuser) && !empty($zapuser)){
				foreach($zapuser as $user){
				?>
				<div class="col-md-12">
					<div class="frnd-list thumbnail">
						<div class="col-md-2">
							<a href="<?php echo base_url('users/profile').'/'.$user['userid']; ?>">
							<img src="<?php echo base_url(); ?>assets/uploads/.thumbs/images/zap/<?php echo $user['photo'] == '' ? DEFAULT_IMG : $user['photo'] ; ?>" class="" height="75" width="75">
							</a>
						</div>
						<div class="col-md-10">
							<a href="<?php echo base_url('users/profile').'/'.$user['userid']; ?>"><h4><?=$user['firstname'].' '.$user['lastname']?></h4></a>
							
							<div class="desc">
								<!--<p class="text-primary"><span class="glyphicon glyphicon-user"></span> Friends with Subharanjan Mantri and other friends</p>
								<p class="text-primary"><span class="glyphicon glyphicon-bookmark"></span> Studied at BPUT '11</p>
								<p class="text-primary"><span class="glyphicon glyphicon-heart"></span> Lives in Bangalore, India</p>-->
								<div class="btn-group">
									<?php if($user['friend']==1){?>
									<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-user"></span> Friend</button>
									<?}else{?>
									<button type="button" class="btn btn-default" id="add_friend<?=$user['userid']?>" <?php echo $user['friend_request']==1 ? "disabled='disabled'" : '';?> onclick="friendaction('<?php echo $user['userid'];?>','add')"><span class="glyphicon glyphicon-user"></span> <?php echo $user['friend_request']==1 ? "Friend Request Sent" : 'Add Friend';?></button>
									<?}?>
									<!--<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-envelope"></span> Message</button>-->
								</div>
								
								<button type="button" class="btn btn-default pull-right" id="cancel_friend<?=$user['userid']?>" style="<?php echo $user['friend_request']==1 ? "display:block" : 'display:none';?>" onclick="friendaction('<?php echo $user['userid'];?>','cancel')" ><span class="glyphicon glyphicon-envelope"></span>Cancel Request</button>
								<button type="button" class="btn btn-default pull-right" id="delete_friend<?=$user['userid']?>" style="<?php echo $user['friend']==1 ? "display:block" : 'display:none';?>" onclick="friendaction('<?php echo $user['userid'];?>','delete')" ><span class="glyphicon glyphicon-envelope"></span>Delete Friend</button>
								
							</div>
						</div>
					</div>
				</div>
				<?}}?>
			</div>
		
<script>
function friendaction(userid,action)
{
	var dataString = "userid=" + userid + "&action=" + action ;
	$.ajax({  
        type: "POST",  
        url: "<?php echo base_url('ajax/friend_request')?>",  
        data: dataString,
		cache: false,
        beforeSend: function() 
        {
			if(action=='add')
			{
				$('#add_friend'+userid).prop('disabled', true);
			}
			else if(action=='cancel')
			{
				$('#add_friend'+userid).prop('disabled', false);
				$('#add_friend'+userid).html('<span class="glyphicon glyphicon-user"></span> Add Friend');
				
			}
        },  
        success: function(response)
        {
            if(response == "requested")
			{
				$('#add_friend'+userid).prop('disabled', true);
				$('#add_friend'+userid).html('<span class="glyphicon glyphicon-user"></span> Friend Request Sent');
				$('#cancel_friend'+userid).show();
			}
			else if(response == "cancel")
			{
				$('#cancel_friend'+userid).hide();
			}
        }
    });
}
</script>